<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#assign currentMenu="personal"/>
    <#include "../common/header.ftl">
    <script src="/js/plugins/jquery-bootstrap/jquery.bootstrap.min.js"></script>
    <script src="/js/My97DatePicker/WdatePicker.js"></script>
    <style type="text/css">
        .modal-body {
            max-height: 750px;
            overflow-y: auto;
        }
        .modal-body img {
            width: 100%;
        }
    </style>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-lg-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-lg-9">
            <div class="row">
                <div class="col-lg-12">
                    <h1 class="page-head-line">私人订制管理</h1>
                </div>
            </div>
            <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/personal/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>关键字:</label>
                    <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入标题/副标题">
                </div>
                <div class="form-group">
                    <label>推荐类型:</label>
                    <select class="form-control" name="type">
                        <option value="-1">全部</option>
                        <option value="1">美食</option>
                        <option value="2">酒店</option>
                        <option value="3">家居</option>
                        <option value="4">其他</option>
                    </select>
                </div>
                <script type="text/javascript">
                    $("#searchForm select[name='type']").val(${qo.type});
                </script>
                <button id="btn_query" class="btn btn-info">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <button type="button" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 新增
                </button>
            </form>

            <table class="table table-striped table-hover">
                <tr>
                    <th>序号</th>
                    <th>封面</th>
                    <th>标题</th>
                    <th>副标题</th>
                    <th>发布时间</th>
                    <th>私人订制类型</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                <#list pageInfo.list as entity>
                    <tr>
                        <td>${entity_index + 1}</td>
                        <td><img src="${entity.coverUrl}" width="100"/></td>
                        <td>${entity.title}</td>
                        <td>${entity.subTitle}</td>
                        <td>${(entity.releaseTime?string("yyyy-MM-dd HH:mm:ss"))!}</td>
                        <td>${entity.typeName}</td>
                        <td>${entity.stateName}</td>
                        <td>
                            <a role="button" class="btn btn-warning btn-xs inputBtn" data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-pencil"></span> 修改
                            </a>
                        </td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>

<#-- 修改私人订制 -->
<div id="inputModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title">私人订制内容</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/personal/saveOrUpdate.do" method="post"
                      enctype="multipart/form-data" id="editForm">
                    <input type="hidden" name="id"/>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">标题：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="title"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">副标题：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="subTitle"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">封面：</label>
                        <div class="col-lg-6">
                            <img id="coverUrl" style="width: 100%"/>
                            <input type="file" class="form-control" name="img"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">私人订制类型：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="type">
                                <option value="1">美食</option>
                                <option value="2">酒店</option>
                                <option value="3">家居</option>
                                <option value="4">其他</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">状态：</label>
                        <div class="col-lg-6">
                            <select class="form-control" name="state">
                                <option value="0">草稿</option>
                                <option value="1">发布</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <textarea name="personalContent.content" id="ckeditor"></textarea>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary submitBtn">保存</button>
            </div>
        </div>
    </div>
</div>
<script src="/js/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
    $(function () {
        //ckeditor富文本插件的使用
        var ck = CKEDITOR.replace("ckeditor");
        //弹出设置推荐的模态框
        $(".inputBtn").click(function () {
            //清空模态框中的数据
            $("#editForm input").val("");
            $("#coverUrl").attr("src","")
            var json = $(this).data("json");
            if (json) {
                //如果是编辑操作我们还需要查富文本内容,使用id去查
                $.get("/personal/getContentById.do", {id: json.id}, function (data) {
                    ck.setData(data);
                });
                $("#editForm input[name='id']").val(json.id);
                $("#coverUrl").attr("src", json.coverUrl)
                $("#editForm select[name='state']").val(JSON.stringify(json.state));
                $("#editForm input[name='title']").val(json.title);
                $("#editForm input[name='subTitle']").val(json.subTitle);
                $("#editForm input[name='state']").val(json.state);
                $("#editForm input[name='type']").val(json.type);
                $("#editForm select[name='type']").val(JSON.stringify(json.type));
            }
                $("#inputModal").modal('show');

            });

        $(".submitBtn").click(function () {
            $("#editForm").submit();
        })

    });
</script>
</body>
</html>